<?php
/*
 * @Author: your name
 * @Date: 2020-10-15 10:07:53
 * @LastEditTime: 2020-12-31 17:06:57
 * @LastEditors: Please set LastEditors
 * @Description: 端口伪装验证器
 * @FilePath: /special/application/adminapiv3/validate/PortMaskValidate.php
 */
namespace app\adminapiv3\validate;

use think\Validate;

class PortMaskValidate extends Validate
{
    protected $rule = [
        //主机id
        'host_id|主机ID' => 'require|number|length:1,8',
        //主机端口号
        'port|端口号' => 'number|between:1,65535',
        //协议 6 tcp 17 udp 1 icmp
        'protocols|网络协议' => 'in:1,6,17',
        //伪装状态 1开启 0关闭
        'status|伪装状态' => 'in:0,1',
        //中间键常用端口 
        'middleware|中间键常用端口' => 'require|regex:^\d{1,5}(,\d{1,5}){0,30}$',
        //数据库常用端口
        'sql|数据库常用端口' => 'require|regex:^\d{1,5}(,\d{1,5}){0,30}$',
        //常用端口
        'standard|标准伪装端口' => 'require|regex:^\d{1,5}(,\d{1,5}){0,30}$',
        //TCP协议端口
        'tcp|TCP协议的端口' => 'regex:^\d{1,5}(,\d{1,5}){0,30}$',
        //UDP协议端口
        'udp|UDP协议的端口' => 'regex:^\d{1,5}(,\d{1,5}){0,30}$',
    ];

    protected $message = [
        'protocols.in' => '网络协议格式错误',
        'status.in' => '伪装状态格式错误',
    ];

    protected $scene = [
        //列表搜索
        'listFilter' => ['port','protocols','status','host_id'],
        //端口伪装开启
        'maskOn' => ['middleware','sql','standard','tcp','udp'],
        //单个主机id
        'oneHostId' => ['host_id']
        //端口伪装关闭
        // 'maskOff' => ['host_id'],
    ];

    public function sceneBulkHostId ()
    {
        $this->only(['host_id'])->remove('host_id', 'number')->append('host_id', 'regex:^\d{1,8}(,\d{1,8}){0,30}$');
    }
}